package com.nut.spp.api.client;

import com.nut.spp.api.req.ClientLoginReq;
import com.nut.spp.common.Result;
import com.nut.spp.service.MemberService;
import com.nut.spp.util.IpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 鉴权服务
 */
@RestController
@RequestMapping("/client/auth")
@Validated
@Slf4j
public class AuthController {

    @Autowired
    private MemberService memberService;

    @GetMapping("/test")
    public Result test() {
        return Result.ok();
    }

    @PostMapping("login")
    public Result<String> login(@RequestBody ClientLoginReq req, HttpServletRequest request) {
        String ip = IpUtil.client(request);
        req.setIp(ip);
        return memberService.clientLogin(req);
    }

    @PostMapping("register")
    public Result<String> register(@RequestBody ClientLoginReq req, HttpServletRequest request) {
        String ip = IpUtil.client(request);
        req.setIp(ip);
        return memberService.registerLogin(req);
    }



}
